<!--
  ###license-information-start###
  E-PIX - Enterprise Patient Identifier Cross-referencing
  __
  Copyright (C) 2009 - 2017 The MOSAIC Project - Institut fuer Community Medicine der
  							Universitaetsmedizin Greifswald - mosaic-projekt@uni-greifswald.de
  							concept and implementation
  							c. schack, d.langner, l. geidel
  							web client
  							a. blumentritt
  							g. weiher
  							please cite our publications
  							http://dx.doi.org/10.3414/ME14-01-0133
  							http://dx.doi.org/10.1186/s12967-015-0545-6
  __
  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  ###license-information-end###
  -->
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:jstl="http://java.sun.com/jsp/jstl/functions"
	xmlns:customs = "http://java.sun.com/jsf/composite/customs">
<!-- author: mathiasd -->
<h:body>
	<ui:composition template="/template/ths_templ.xhtml">
	
	<ui:define name="meta_tags">
			<style media="screen" type="text/css">
				#customLogo, #logo {
					margin: 0 10px 10px 10px !important;
					height: auto !important;
				}
				#customLogo img, #logo img {
					height: 45px !important;
				}
				#header h1 {
					padding-top: 14px !important;
				}
				.littleHeadline {
					font-size: 1.1em;
					padding: 0 0 4px 0;
					font-family: Arial,sans-serif;
					display: inline-block;
				}
			</style>
		</ui:define>

		<!-- method is called when page is loaded -->
		<ui:define name="start">
			<h:outputText value="#{criticalMatches.receiveTableData()}" />
		</ui:define>

		<ui:define name="customLogo">
			<a href="index.xhtml"><img src="#{request.contextPath}/img/epix_logo.png" /></a>
		</ui:define>

		<ui:define name="header_title">
			<h:outputFormat value="#{msg['general.headertitle']}" />
		</ui:define>

		<ui:define name="title">
			<h:outputFormat value="#{msg['general.title']}" />
		</ui:define>

		<ui:define name="info">
			<customs:headerMenu activeIndex="0" />
		</ui:define>

		<ui:define name="content">
			<p:growl autoUpdate="true"></p:growl>
			<p:ajaxStatus
				style="width:64px;height:64px;position:fixed;right:5px;bottom:5px">
				<f:facet name="start">
					<p:graphicImage value="/img/ajax-loader_pf.gif" />
				</f:facet>

				<f:facet name="complete">
					<h:outputText value="" />
				</f:facet>
			</p:ajaxStatus>
			<div id="contentBox">
				<h:form id="main">

					<h:panelGrid columns="2">
						<p:dataTable id="criticalMatches" var="match" filteredValue="#{criticalMatches.filteredMatchesList}" widgetVar="criticalMatchesTable"
							value="#{criticalMatches.matchesModel}" selectionMode="single"
							selection="#{criticalMatches.selectedMatch}" scrollable="true"
							scrollHeight="122" scrollRows="10"
							emptyMessage="#{msg['resolve.label.norecordsfoundsmessage']}"
							styleClass="dataTable whiteBackground">

							<!-- Ajax-events for selecting and unselecting of rows -->
							<p:ajax event="rowSelect"
								listener="#{criticalMatches.onRowSelectMatch}"
								update=":main:linkedPersonsPanel,:main:criticalDetailsPanel" />
							<p:ajax event="rowUnselect"
								listener="#{criticalMatches.onRowUnselectMatch}"
								update=":main:linkedPersonsPanel,:main:criticalDetailsPanel" />
							<f:facet name="header">
								<h:outputLabel styleClass="littleHeadline" style="margin: 5px 0px 0px -3px;float:left;font-weight:normal">
									<h:outputFormat value="#{msg['resolve.label.matchesTableHeader']}">
										<f:param value="#{criticalMatches.matchesList.size()}" />
									</h:outputFormat>
								</h:outputLabel>
								<div align="right">
									<p:inputText id="globalFilter"
										onkeyup="PF('criticalMatchesTable').filter()" style="width:150px" />
									<p:watermark for="globalFilter" value="filter values"></p:watermark>
								</div>
							</f:facet>
						<!--  	<p:column headerText="#{msg['mpi']}" sortBy="#{match.mpiid}" filterMatchMode="contains" filterBy="#{match.mpiid}" filterStyle="display:none">
								<h:outputText value="#{match.mpiid}" />
							</p:column> -->
							<p:column headerText="#{msg['lastName']}" sortBy="#{match.name}" filterMatchMode="contains" filterBy="#{match.name}" filterStyle="display:none">
								<h:outputText value="#{match.name}" />
							</p:column>
							<p:column headerText="#{msg['firstName']}" sortBy="#{match.firstName}" filterMatchMode="contains" filterBy="#{match.firstName}" filterStyle="display:none">
								<h:outputText value="#{match.firstName}" />
							</p:column>
							<p:column headerText="#{msg['gender']}"
								style="text-align:center;" sortBy="#{match.sex}" filterMatchMode="contains" filterBy="#{match.sex}" filterStyle="display:none">
								<h:outputText value="#{match.sex}" />
							</p:column>
							<p:column headerText="#{msg['birthDate']}"
								style="text-align:center;" sortBy="#{match.birthdate}" filterMatchMode="contains" filterBy="#{match.birthdate}" filterStyle="display:none">
								<h:outputText value="#{match.birthdate}" />
							</p:column>

							<p:column headerText="#{msg['zip']}" sortBy="#{match.postalCode}" filterMatchMode="contains" filterBy="#{match.postalCode}" filterStyle="display:none">
								<h:outputText value="#{match.postalCode}" />
							</p:column>

							<p:column
								headerText="#{msg['resolve.label.tableheader.lastchange']}"
								sortBy="#{match.lastChange}" filterBy="#{match.lastChange}" filterMatchMode="contains" filterStyle="display:none">
								<h:outputText value="#{match.lastChange}" />
							</p:column>
						</p:dataTable>

					</h:panelGrid>
					<div class="alignRight">
						<p:commandButton id="refresh"
							value="#{msg['resolve.label.buttonRefreshList']}" ajax="true"
							action="#{criticalMatches.receiveTableData()}" update=":main" />
					</div>
					<div class="clear"></div>
					<div class="spacer"></div>

					<p:outputPanel id="linkedPersonsPanel">
						<p:outputPanel
							rendered="#{not empty criticalMatches.selectedMatch}">

							<h:outputLabel styleClass="littleHeadline" style="margin: 0px 0px -3px 3px;">
								<h:outputFormat id="linkedPersonSize" value="#{msg['resolve.info.linkedPerson']}">
									<f:param value="#{criticalMatches.linksList.size()}" />
								</h:outputFormat>
							</h:outputLabel>

							<h:panelGrid columns="2">
								<p:dataTable id="linkedPersons" var="link"
									value="#{criticalMatches.linksModel}" selectionMode="single"
									selection="#{criticalMatches.selectedLink}" scrollable="true"
									scrollHeight="122" liveScroll="true" scrollRows="10" 
									lazy="true"
									emptyMessage="#{msg['resolve.label.norecordsfoundsmessage']}"
									styleClass="dataTable whiteBackground">

									<!-- Ajax-events for selecting and unselecting of rows -->
									<p:ajax event="rowSelect"
										listener="#{criticalMatches.onRowSelectLink}"
										update=":main:criticalDetailsPanel,:dialog_form"/>
									<p:ajax event="rowUnselect"
										listener="#{criticalMatches.onRowUnselectLink}"
										update=":main:criticalDetailsPanel,:dialog_form"/>

									<!--  <p:column headerText="#{msg['mpi']}">
										<h:outputText value="#{link.mpiid}" />
									</p:column> -->
									<p:column headerText="#{msg['lastName']}">
										<h:outputText value="#{link.name}" />
									</p:column>
									<p:column headerText="#{msg['firstName']}">
										<h:outputText value="#{link.firstName}" />
									</p:column>
									<p:column headerText="#{msg['gender']}"
										style="text-align:center;">
										<h:outputText value="#{link.sex}" />
									</p:column>
									<p:column headerText="#{msg['birthDate']}"
										style="text-align:center;">
										<h:outputText value="#{link.birthdate}" />
									</p:column>

									<p:column headerText="#{msg['zip']}">
										<h:outputText value="#{link.postalCode}" />
									</p:column>

									<p:column
										headerText="#{msg['resolve.label.tableheader.lastchange']}">
										<h:outputText value="#{link.lastChange}"/>
									</p:column>
									<p:column
										headerText="#{msg['probability']}">
										<h:outputText value="#{link.probability}">
											<f:convertNumber maxFractionDigits="3"/>
										</h:outputText>
									</p:column>
								</p:dataTable>
							</h:panelGrid>

							<div align="right">
								<p:commandButton id="removeLinks"
									value="#{msg['resolve.label.buttonRemoveLinks']}"
									onclick="PF('confirmationRemoveLinks').show()" type="button"
									ajax="true"
									disabled="#{criticalMatches.removeLinksButtonDisable}"
									update=":main">
								</p:commandButton>
							</div>

							<div class="clear"></div>
							<div class="spacer"></div>
						</p:outputPanel>
					</p:outputPanel>
					<p:outputPanel id="criticalDetailsPanel">
						<p:outputPanel>
							<h:panelGrid columns="3">
								<h:column>
									<h:outputText styleClass="littleHeadline" value="#{msg['resolve.label.detailsSelectedMatch']}" />
									<br />
									<!-- disabled inputTextArea for displaying area even when content is empty -->
									<p:dataTable var="detailKey" style="width:400px; min-height:600px;" styleClass="hide-column-names" emptyMessage="#{msg['resolve.label.noMatchSelected']}"
										value="#{criticalMatches.criticalMatchDetails.detailKeys}"
										rowStyleClass="#{criticalMatches.linkedMatchDetails.get(detailKey) eq criticalMatches.criticalMatchDetails.get(detailKey) or empty criticalMatches.selectedLink  ? '':'critcalMatchDifference'}">
										<p:column>#{msg[detailKey]}</p:column>
										<p:column>#{criticalMatches.criticalMatchDetails.get(detailKey)}</p:column>
									</p:dataTable>
								</h:column>
								<h:column >
									<p:outputPanel styleClass="resolveButtonBlock">
										<p:commandButton id="toRight" icon="ui-icon-arrowthick-1-e"
										title="#{msg['resolve.label.buttonToRight']}" ajax="true"
										value="#{msg['resolve.label.buttonToRight']}" update=":main"
										onclick="PF('confirmationAssignRight').show()" type="button"
										disabled="#{criticalMatches.assignButtonDisable}"
										styleClass="resolveButton" />
									<p:tooltip for="toRight">
										<h:outputFormat
											value="#{msg['resolve.tooltip.buttonToRight']}">
											<f:param value="#{criticalMatches.selectedMatch.mpiid}" />
											<f:param value="#{criticalMatches.selectedLink.mpiid}" />
											<f:param value="#{criticalMatches.thsCode}" /> 
										</h:outputFormat>
									</p:tooltip>

									<p:commandButton id="toLeft" icon="ui-icon-arrowthick-1-w"
										title="#{msg['resolve.label.buttonToLeft']}" ajax="true"
										value="#{msg['resolve.label.buttonToLeft']}"
										onclick="PF('confirmationAssignLeft').show()" type="button"
										actionListener="#{criticalMatches.resetExplanation()}"
										disabled="#{criticalMatches.assignButtonDisable}"
										update=":main" styleClass="resolveButton" />
									<p:tooltip for="toLeft">
										<h:outputFormat value="#{msg['resolve.tooltip.buttonToLeft']}">
											<f:param value="#{criticalMatches.selectedLink.mpiid}" />
											<f:param value="#{criticalMatches.selectedMatch.mpiid}" />
											<f:param value="#{criticalMatches.thsCode}" /> 
										</h:outputFormat>
									</p:tooltip>


									<p:commandButton id="unlink" icon="ui-icon-link"
										title="#{msg['resolve.label.buttonUnlink']}" ajax="true"
										value="#{msg['resolve.label.buttonUnlink']}"
										onclick="PF('confirmationUnlink').show()" type="button"
										disabled="#{criticalMatches.assignButtonDisable}"
										update=":main" styleClass="resolveButton" />
									<p:tooltip for="unlink">
									<!-- 	<h:outputFormat value="#{msg['resolve.tooltip.buttonUnlink']}"> -->
									
									<h:outputFormat value="#{msg['reslove.tooltip.buttonUnlinkWithTHSCode']}">
											<f:param value="#{criticalMatches.selectedMatch.mpiid}" />
											<f:param value="#{criticalMatches.selectedLink.mpiid}" />
											<f:param value="#{criticalMatches.thsCode}" /> 
											
										</h:outputFormat>
									</p:tooltip>
									</p:outputPanel>
									


								</h:column>
								<h:column>
									<h:outputText styleClass="littleHeadline" value="#{msg['resolve.label.detailsSelectedPerson']}" />
									<br />
									<!-- readonly inputTextArea, damit auch bei leerem Inhalt das Feld angezeigt wird -->
									<p:dataTable var="detailKey" style="width:400px; min-height:600px;" styleClass="hide-column-names" emptyMessage="#{msg['resolve.label.noLinkSelected']}"
										value="#{criticalMatches.linkedMatchDetails.detailKeys}"
										rowStyleClass="#{criticalMatches.linkedMatchDetails.get(detailKey) eq criticalMatches.criticalMatchDetails.get(detailKey) or empty criticalMatches.selectedLink ? '':'critcalMatchDifference'}">
										<p:column>#{msg[detailKey]}</p:column>
										<p:column>#{criticalMatches.linkedMatchDetails.get(detailKey)}</p:column>
									</p:dataTable>
								</h:column>
							</h:panelGrid>
						</p:outputPanel>
					</p:outputPanel>


					
				</h:form>
				<h:form id="dialog_form">
				<!-- confirmDialogs for remove- and assign-buttons -->
					<!-- confirmDialog for each button is needed, because the methods are declared within the dialogs -->
					<p:confirmDialog  closable="false" id="toRightDialog"
						header="Assign person (MPI ID #{criticalMatches.selectedMatch.mpiid}) as a new identity"
						width="400" widgetVar="confirmationAssignRight">
						
						
						<f:facet name="message">
							<h:outputText
								value="#{msg['resolve.message.confirmation.assign.part1']}" />
							<br />
							<h:outputText
								value="#{criticalMatches.selectedMatch.name}, #{criticalMatches.selectedMatch.firstName} (MPI ID #{criticalMatches.selectedMatch.mpiid})" />
							<br />
							<h:outputText
								value="#{msg['resolve.message.confirmation.assign.part2']}as a new identity to the person" />
							<br />
							<h:outputText
								value="#{criticalMatches.selectedLink.name}, #{criticalMatches.selectedLink.firstName} (MPI ID #{criticalMatches.selectedLink.mpiid})?" />
							<br />
							
							<br />
							<h:outputText
								value="#{criticalMatches.thsCode}" />
							<br />
							<br />
							<p:outputLabel value="#{msg['resolve.label.explanation']}" />
							<p:inputText id="confirmAssignRight_explanation"
								value="#{criticalMatches.explanation}">
								<p:ajax event="keyup" update="confirmAssignRight"></p:ajax>
								<p:watermark for="confirmAssignRight_explanation"
									value="#{msg['resolve.message.confirmation.explanation']}"></p:watermark>
							</p:inputText>
						<!-- <p:separator></p:separator> -->
						</f:facet>
						<p:commandButton process="@form"
							disabled="#{empty criticalMatches.explanation}" value="Yes"
							id="confirmAssignRight" update=":main,:dialog_form"
							onsuccess="PF('confirmationAssignRight').hide();"
							actionListener="#{criticalMatches.assignToRight()}" />
						<p:commandButton value="No"
							onclick="PF('confirmationAssignRight').hide();" type="button" update=":dialog_form" />
						
					</p:confirmDialog>
					<p:confirmDialog closable="false" id="toLeftDialog"
						header="Assign person (MPI ID #{criticalMatches.selectedLink.mpiid}) as a new identity"
						width="400" widgetVar="confirmationAssignLeft">
						<f:facet name="message">
							<h:outputText
								value="#{msg['resolve.message.confirmation.assign.part1']}" />
							<br />
							<h:outputText
								value="#{criticalMatches.selectedLink.name}, #{criticalMatches.selectedLink.firstName} (MPI ID #{criticalMatches.selectedLink.mpiid})" />
							<br />
							<h:outputText
								value="#{msg['resolve.message.confirmation.assign.part2']}" />
							<br />
							<h:outputText
								value="#{criticalMatches.selectedMatch.name}, #{criticalMatches.selectedMatch.firstName} (MPI ID #{criticalMatches.selectedMatch.mpiid})?" />
							<br />
							<br />
							<h:outputText
								value="#{criticalMatches.thsCode}" />
							<br />
							<br />
							<p:outputLabel value="#{msg['resolve.label.explanation']}" />
							<p:inputText id="confirmAssignLeft_explanation"
								value="#{criticalMatches.explanation}">
								<p:ajax event="keyup" update="confirmAssignLeft"></p:ajax>
								<p:watermark for="confirmAssignLeft_explanation"
									value="#{msg['resolve.message.confirmation.explanation']}"></p:watermark>
							</p:inputText>
						</f:facet>
						<p:commandButton process="toLeftDialog:"
							disabled="#{ empty criticalMatches.explanation}" value="Yes"
							id="confirmAssignLeft" update=":main,:dialog_form"
							onsuccess="PF('confirmationAssignLeft').hide()"
							actionListener="#{criticalMatches.assignToLeft()}" />
						<p:commandButton value="No"
							onclick="PF('confirmationAssignLeft').hide()" type="button" update=":dialog_form" />
						
					</p:confirmDialog>
					<p:confirmDialog closable="false" id="unlinkDialog"
						header="Remove Link" width="400" widgetVar="confirmationUnlink">
						<f:facet name="message">
							<h:outputText
								value="#{msg['resolve.message.confirmation.removelink.part1']}" />
							<br />
							<h:outputText
								value="#{criticalMatches.selectedMatch.name}, #{criticalMatches.selectedMatch.firstName} (MPI ID #{criticalMatches.selectedMatch.mpiid})" />
							<br />
							<h:outputText
								value="#{msg['resolve.message.confirmation.removelink.part2']}" />
							<br />
							<h:outputText
								value="#{criticalMatches.selectedLink.name}, #{criticalMatches.selectedLink.firstName} (MPI ID #{criticalMatches.selectedLink.mpiid})?" />
							<br />
							<br />
							<h:outputText
								value="#{criticalMatches.thsCode}" />
							<br />
							<br />
							<p:outputLabel value="#{msg['resolve.label.explanation']}" />
							<p:inputText id="confirmUnlink_explanation"
								value="#{criticalMatches.explanation}">
								<p:ajax event="keyup" update="confirmUnlink"></p:ajax>
								<p:watermark for="confirmUnlink_explanation"
									value="#{msg['resolve.message.confirmation.explanation']}"></p:watermark>
							</p:inputText>
						</f:facet>
						<p:commandButton process="unlinkDialog:"
							disabled="#{empty criticalMatches.explanation}" value="Yes"
							id="confirmUnlink" update=":main,:dialog_form"
							onsuccess="PF('confirmationUnlink').hide()"
							actionListener="#{criticalMatches.removeLink()}" />
						<p:commandButton value="No" onclick="PF('confirmationUnlink').hide()" update=":dialog_form"
							type="button" />
					</p:confirmDialog>
					<p:confirmDialog closable="false" id="removeAllDialog"
						header="Remove all links" width="400"
						widgetVar="confirmationRemoveLinks">
						<f:facet name="message">
							<h:outputText
								value="#{msg['resolve.message.confirmation.removeall']}" />
							<br />
							<h:outputText
								value="(Total: #{criticalMatches.linksList.size()}) from the Person" />
							<br />
							<h:outputText
								value="#{criticalMatches.selectedMatch.name}, #{criticalMatches.selectedMatch.firstName} (MPI ID #{criticalMatches.selectedMatch.mpiid})?" />
							<br />
							<br />
							<p:outputLabel value="#{msg['resolve.label.explanation']}" />
							<p:inputText id="confirmRemoveLinks_explanation"
								value="#{criticalMatches.explanation}">
								<p:ajax event="keyup" update="confirmRemoveLinks"></p:ajax>
								<p:watermark for="confirmRemoveLinks_explanation"
									value="#{msg['resolve.message.confirmation.explanation']}"></p:watermark>
							</p:inputText>
						</f:facet>
						<p:commandButton process="removeAllDialog:"
							disabled="#{ empty criticalMatches.explanation}" value="Yes"
							id="confirmRemoveLinks" update=":main,:dialog_form"
							action="PF('confirmationRemoveLinks').hide()"
							actionListener="#{criticalMatches.removeLinks}" />
						<p:commandButton value="No"
							onclick="PF('confirmationRemoveLinks').hide()" type="button" update=":dialog_form" />
					</p:confirmDialog>
				</h:form>
			</div>
		</ui:define>

		<ui:define name="version">
			<h:outputText value="${display_version}" />
		</ui:define>

	</ui:composition>
</h:body>
</html>
